package com.lanou.timeline.web.controller;

import com.lanou.timeline.entity.Userinfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;


@RestController
public class Atest {


//        //连接本地的 Redis 服务
//        Jedis jedis = new Jedis("172.16.29.104",6379);
//        System.out.println("连接成功");
//        //设置 redis 字符串数据
//        jedis.set("runoobkey", "www.runoob.com");
//        // 获取存储的数据并输出
//        System.out.println("redis 存储的字符串为: "+ jedis.get("runoobkey"));



        private static final Logger logger = LoggerFactory.getLogger(Atest.class);

        @Autowired
        RedisTemplate redisTemplate;

        @Autowired
        StringRedisTemplate stringRedisTemplate;

        @RequestMapping("/addactiveuser")
        public void addActiveUser(){
            ZSetOperations<String,Object> userActive = redisTemplate.opsForZSet();
            TimelineController timelineController = new TimelineController();
            List<Userinfo> userinfos = timelineController.selectUserActive();
            for (int i = 0; i < userinfos.size(); i++) {
                userActive.add("userActive",userinfos.get(i),i);
            }
            Set userActive1 = redisTemplate.opsForZSet().range("userActive", 0, -1);
            List userlist = new ArrayList();
            for (Object o : userActive1) {
                userlist.add(o);
            }

        }
}
